// pages/news/news.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    inDoor: [],
    outDoor: [],
    typeDoor: [],
    faceImg: '',
  },
  typeDoor(e) {
    this.setData({
      typeDoor: e.detail.all
    })
    let img = e.detail.current[0];
    this.upfile(img, 'typeDoor');
  },
  inDoor(e) {
    this.setData({
      inDoor: e.detail.all
    })
    let img = e.detail.current[0];
    this.upfile(img, 'inDoor');
  },
  outDoor(e) {
    let img = e.detail.current[0];
    this.upfile(img, 'outDoor')
  },
  faceImg(e) {
    let img = e.detail.current[0];
    this.upfile(img, 'faceImg')
  },
  upfile(img, type) {
    wx.uploadFile({
      url: 'http://local.da.com/api/upfile', //仅为示例，非真实的接口地址
      filePath: img,
      name: 'file',
      header: {
        'Content-Type': 'application/json;charset=UTF-8',
        'token': wx.getStorageSync('token').token
      },
      success: (res) => {
        let imgPath = JSON.parse(res.data)
        if (type == 'outDoor') {
          this.setData({
            outDoor: [...this.data.outDoor, imgPath.data]
          })
        } else if (type == 'inDoor') {
          this.setData({
            inDoor: [...this.data.inDoor, imgPath.data]
          })
        } else if (type == 'typeDoor') {
          this.setData({
            typeDoor: [...this.data.typeDoor, imgPath.data]
          })
        } else if (type == 'faceImg') {
          this.setData({
            faceImg: imgPath.data
          })
        }
      },
      fail(res) {
        console.log(res)
      }
    })
  },
  warning() {
    let inDoor = this.data.inDoor;
    let outDoor = this.data.outDoor;
    let typeDoor = this.data.typeDoor;
    let faceImg = this.data.faceImg;
  },
  /**
  * 生命周期函数--监听页面初次渲染完成
  */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})